package com.groupfifteen.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.groupfifteen.entity.SysAdminEntity;
import com.groupfifteen.entity.SysUserEntity;
import com.groupfifteen.service.SysAdminService;
import com.groupfifteen.service.SysUserService;
import com.groupfifteen.vo.SysAdminVo;
import com.groupfifteen.vo.SysUserVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 管理员管理
 *
 */
@Slf4j
@RestController
@RequestMapping("backend/admin")
public class SysAdminController {

    @Autowired
    private SysAdminService sysAdminService;

    @PostMapping("/query")
    public IPage Query(@RequestBody SysAdminVo sysAdminVo) {

        SysAdminEntity sysAdminEntity = new SysAdminEntity();
        sysAdminEntity.setAdminId(sysAdminVo.getAdminId());
        sysAdminEntity.setAdminName(sysAdminVo.getAdminName());
        sysAdminEntity.setPwd(sysAdminVo.getPwd());

        IPage<SysAdminEntity> page = sysAdminService.Query(sysAdminEntity,1,10);
        return page;
    }
    //ASDFGH
    @PostMapping("addsysadmin")
    public String AddSysAdmin(@RequestBody SysAdminEntity sysAdminEntity) {
        Integer result = sysAdminService.AddSysAdmin(sysAdminEntity);
        if (result > 0) {
            return "success";
        } else {
            return "fail";
        }
    }
    //
    @DeleteMapping("/deletesysadmin/{adminId}")
    public String DeleteSysAdmin(@PathVariable("adminId") Integer adminId) {
        Integer result = sysAdminService.DeleteSysAdmin(adminId);
        if (result > 0) {
            return "success";
        } else {
            return "fail";
        }
    }

    @GetMapping("/getsysadmin/{adminId}")
    public SysAdminEntity GetSysAdmin(@PathVariable("adminId") Integer adminId) {
        SysAdminEntity result = sysAdminService.GetSysAdmin(adminId);
        if (result != null) {
            return result;
        } else {
            return null;
        }
    }

    @PutMapping("/updatesysadmin/{id}")
    public String UpdateSysuser(@PathVariable("id") int id,@RequestBody SysAdminEntity sysAdminEntity) {
        sysAdminEntity.setAdminId(id);
        Integer result = sysAdminService.UpdateSysAdmin(sysAdminEntity);
        if (result > 0) {
            return "success";
        } else {
            return "fail";
        }
    }
    //asdfgfsdfdsffdsf
    @PostMapping("getinfo")
    public String Getinfo() {
        return "success";
    }

}